/*
This file is part of JChip8BR.

JChip8BR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

JChip8BR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JChip8BR.  If not, see <http://www.gnu.org/licenses/>.
 */
package jchip8br.gui;

import java.awt.Color;
import java.awt.Window;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import jchip8br.core.Emulator;
import jchip8br.core.eAssemblerType;
import jchip8br.core.eInstruction;
import jchip8br.util.Util;
import jchip8br.video.Engine;

/**
 * @author dreampeppers99
 */
public class Main extends javax.swing.JFrame {

    private Emulator emulator;
    private Thread emulatorThread;

    private File lastFileSelected;

    private static String fileToLoad;

    /** Creates new form Main */
    public Main() {
        initComponents();

        eInstruction.SetAssemblerType(eAssemblerType.MichaelTorenWay);
        if(!fileToLoad.isEmpty())
            LoadFile(new File(fileToLoad));

        refresh();
    }

    // sets state for the 4 debug/execute mode changes button to suit the
    // currently selected state
    public void SetButtonStates(boolean paused, boolean stopped)
    {
        //jBtnPause , only possible in RUN
        //jBtnStop  , only possible in RUN
        if(!paused)
        {
            jBtnPause.setEnabled(true);
            jBtnStop.setEnabled(true);
            jBtnRun.setEnabled(false);
            jBtnStep.setEnabled(false);
        }
        else
        {
            jBtnPause.setEnabled(false);
            jBtnStop.setEnabled(false);
            jBtnRun.setEnabled(true);
            jBtnStep.setEnabled(true);
        }
        
        //jBtnRun   , only possible when stopped/pause , should work as Continue
        //jBtnStep  , only possible when in PAUSE
    }

    private Color getColor(String color) {
        if (color.equals("BLACK")) {
            return Color.BLACK;
        }
        if (color.equals("BLUE")) {
            return Color.BLUE;
        }
        if (color.equals("CYAN")) {
            return Color.CYAN;
        }
        if (color.equals("DARK_GRAY")) {
            return Color.DARK_GRAY;
        }
        if (color.equals("GREEN")) {
            return Color.GREEN;
        }
        if (color.equals("MAGENTA")) {
            return Color.MAGENTA;
        }
        if (color.equals("ORANGE")) {
            return Color.ORANGE;
        }
        if (color.equals("RED")) {
            return Color.RED;
        }
        if (color.equals("WHITE")) {
            return Color.WHITE;
        }
        if (color.equals("YELLOW")) {
            return Color.YELLOW;
        }
        return Color.BLACK;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jInternalDebugRegister = new javax.swing.JInternalFrame();
        jLabel1 = new javax.swing.JLabel();
        jTxtPC = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTxtSP = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTxtI = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTxtV0 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTxtV3 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTxtV6 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTxtV9 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTxtVC = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTxtV1 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTxtV4 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTxtV7 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jTxtVA = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jTxtVD = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jTxtV2 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTxtV5 = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jTxtV8 = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jTxtVB = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jTxtVE = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jTxtVF = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTxtStack = new javax.swing.JTextArea();
        jTxtDT = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jTxtST = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jInternalDebugMemory = new javax.swing.JInternalFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTxtMemory = new javax.swing.JTextArea();
        jInternalDissambler = new javax.swing.JInternalFrame();
        jBtnRun = new javax.swing.JButton();
        jBtnPause = new javax.swing.JButton();
        jBtnStep = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTxtDissambler = new javax.swing.JTextArea();
        jBtnClear = new javax.swing.JButton();
        jBtnStop = new javax.swing.JButton();
        jBtnRefresh = new javax.swing.JButton();
        jBtnShowAssembler = new javax.swing.JButton();
        jBtnReset = new javax.swing.JButton();
        jInternalConfiguration = new javax.swing.JInternalFrame();
        jSliderSpeed = new javax.swing.JSlider();
        jLabel24 = new javax.swing.JLabel();
        jCboBackgroundColor = new javax.swing.JComboBox();
        jCboObjectsColor = new javax.swing.JComboBox();
        jCboPixelShape = new javax.swing.JComboBox();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jTxt0x01 = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        jCboScreenSize = new javax.swing.JComboBox();
        jTxt0x02 = new javax.swing.JTextField();
        jTxt0x03 = new javax.swing.JTextField();
        jTxt0xC = new javax.swing.JTextField();
        jTxt0xD = new javax.swing.JTextField();
        jTxt0x06 = new javax.swing.JTextField();
        jTxt0x05 = new javax.swing.JTextField();
        jTxt0x04 = new javax.swing.JTextField();
        jTxt0x07 = new javax.swing.JTextField();
        jTxt0x08 = new javax.swing.JTextField();
        jTxt0x09 = new javax.swing.JTextField();
        jTxt0xE = new javax.swing.JTextField();
        jTxt0xF = new javax.swing.JTextField();
        jTxt0xB = new javax.swing.JTextField();
        jTxt0x00 = new javax.swing.JTextField();
        jTxt0xA = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jLabel40 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        jLabel43 = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        jLabel45 = new javax.swing.JLabel();
        jBtnApplyConfiguration = new javax.swing.JButton();
        jLabel28 = new javax.swing.JLabel();
        jLabel46 = new javax.swing.JLabel();
        jTxtFrames = new javax.swing.JTextField();
        jLabel47 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JChip8BR - Ugly implemented by dreampeppers99");

        jInternalDebugRegister.setClosable(true);
        jInternalDebugRegister.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalDebugRegister.setTitle("Debug - Registers");
        jInternalDebugRegister.setVisible(true);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel1.setForeground(new java.awt.Color(0, 0, 153));
        jLabel1.setText("PC:");

        jTxtPC.setBackground(new java.awt.Color(0, 0, 0));
        jTxtPC.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtPC.setForeground(new java.awt.Color(0, 255, 0));
        jTxtPC.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtPC.setText("0x000");
        jTxtPC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtPCActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel2.setForeground(new java.awt.Color(0, 0, 153));
        jLabel2.setText("SP:");

        jTxtSP.setBackground(new java.awt.Color(0, 0, 0));
        jTxtSP.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtSP.setForeground(new java.awt.Color(0, 255, 0));
        jTxtSP.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtSP.setText("0x000");
        jTxtSP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtSPActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel3.setForeground(new java.awt.Color(0, 0, 153));
        jLabel3.setText("I:");

        jTxtI.setBackground(new java.awt.Color(0, 0, 0));
        jTxtI.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtI.setForeground(new java.awt.Color(0, 255, 0));
        jTxtI.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtI.setText("0x000");
        jTxtI.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtIActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel4.setForeground(new java.awt.Color(0, 0, 153));
        jLabel4.setText("Data Registers");

        jLabel5.setForeground(new java.awt.Color(0, 0, 153));
        jLabel5.setText("V0:");

        jTxtV0.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV0.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV0.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV0.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV0.setText("0x000");
        jTxtV0.setToolTipText("0");
        jTxtV0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel6.setForeground(new java.awt.Color(0, 0, 153));
        jLabel6.setText("V3:");

        jTxtV3.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV3.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV3.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV3.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV3.setText("0x000");
        jTxtV3.setToolTipText("3");
        jTxtV3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel7.setForeground(new java.awt.Color(0, 0, 153));
        jLabel7.setText("V6:");

        jTxtV6.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV6.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV6.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV6.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV6.setText("0x000");
        jTxtV6.setToolTipText("6");
        jTxtV6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel8.setForeground(new java.awt.Color(0, 0, 153));
        jLabel8.setText("V9:");

        jTxtV9.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV9.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV9.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV9.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV9.setText("0x000");
        jTxtV9.setToolTipText("9");
        jTxtV9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel9.setForeground(new java.awt.Color(0, 0, 153));
        jLabel9.setText("VC:");

        jTxtVC.setBackground(new java.awt.Color(0, 0, 0));
        jTxtVC.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtVC.setForeground(new java.awt.Color(0, 255, 0));
        jTxtVC.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtVC.setText("0x000");
        jTxtVC.setToolTipText("12");
        jTxtVC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel10.setForeground(new java.awt.Color(0, 0, 153));
        jLabel10.setText("V1:");

        jTxtV1.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV1.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV1.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV1.setText("0x000");
        jTxtV1.setToolTipText("1");
        jTxtV1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel11.setForeground(new java.awt.Color(0, 0, 153));
        jLabel11.setText("V4:");

        jTxtV4.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV4.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV4.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV4.setText("0x000");
        jTxtV4.setToolTipText("4");
        jTxtV4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel12.setForeground(new java.awt.Color(0, 0, 153));
        jLabel12.setText("V7:");

        jTxtV7.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV7.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV7.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV7.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV7.setText("0x000");
        jTxtV7.setToolTipText("7");
        jTxtV7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel13.setForeground(new java.awt.Color(0, 0, 153));
        jLabel13.setText("VA:");

        jTxtVA.setBackground(new java.awt.Color(0, 0, 0));
        jTxtVA.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtVA.setForeground(new java.awt.Color(0, 255, 0));
        jTxtVA.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtVA.setText("0x000");
        jTxtVA.setToolTipText("10");
        jTxtVA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel14.setForeground(new java.awt.Color(0, 0, 153));
        jLabel14.setText("VD:");

        jTxtVD.setBackground(new java.awt.Color(0, 0, 0));
        jTxtVD.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtVD.setForeground(new java.awt.Color(0, 255, 0));
        jTxtVD.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtVD.setText("0x000");
        jTxtVD.setToolTipText("13");
        jTxtVD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel15.setForeground(new java.awt.Color(0, 0, 153));
        jLabel15.setText("V2:");

        jTxtV2.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV2.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV2.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV2.setText("0x000");
        jTxtV2.setToolTipText("2");
        jTxtV2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel16.setForeground(new java.awt.Color(0, 0, 153));
        jLabel16.setText("V5:");

        jTxtV5.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV5.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV5.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV5.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV5.setText("0x000");
        jTxtV5.setToolTipText("5");
        jTxtV5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel17.setForeground(new java.awt.Color(0, 0, 153));
        jLabel17.setText("V8:");

        jTxtV8.setBackground(new java.awt.Color(0, 0, 0));
        jTxtV8.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtV8.setForeground(new java.awt.Color(0, 255, 0));
        jTxtV8.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtV8.setText("0x000");
        jTxtV8.setToolTipText("8");
        jTxtV8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel18.setForeground(new java.awt.Color(0, 0, 153));
        jLabel18.setText("VB:");

        jTxtVB.setBackground(new java.awt.Color(0, 0, 0));
        jTxtVB.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtVB.setForeground(new java.awt.Color(0, 255, 0));
        jTxtVB.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtVB.setText("0x000");
        jTxtVB.setToolTipText("11");
        jTxtVB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel20.setForeground(new java.awt.Color(0, 0, 153));
        jLabel20.setText("VE:");

        jTxtVE.setBackground(new java.awt.Color(0, 0, 0));
        jTxtVE.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtVE.setForeground(new java.awt.Color(0, 255, 0));
        jTxtVE.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtVE.setText("0x000");
        jTxtVE.setToolTipText("14");
        jTxtVE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel21.setForeground(new java.awt.Color(0, 0, 153));
        jLabel21.setText("VF:");

        jTxtVF.setBackground(new java.awt.Color(0, 0, 0));
        jTxtVF.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtVF.setForeground(new java.awt.Color(0, 255, 0));
        jTxtVF.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtVF.setText("0x000");
        jTxtVF.setToolTipText("15");
        jTxtVF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtVRegActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel19.setForeground(new java.awt.Color(0, 0, 153));
        jLabel19.setText("Stack");

        jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane3.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        jTxtStack.setBackground(new java.awt.Color(0, 0, 0));
        jTxtStack.setColumns(20);
        jTxtStack.setEditable(false);
        jTxtStack.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtStack.setForeground(new java.awt.Color(51, 255, 0));
        jTxtStack.setRows(16);
        jTxtStack.setText("01:0x000\n02:0x000\n03:0x000\n04:0x000\n05:0x000\n06:0x000\n07:0x000\n08:0x000\n09:0x000\n10:0x000\n11:0x000\n12:0x000\n13:0x000\n14:0x000\n15:0x000\n16:0x000");
        jScrollPane3.setViewportView(jTxtStack);

        jTxtDT.setBackground(new java.awt.Color(0, 0, 0));
        jTxtDT.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtDT.setForeground(new java.awt.Color(0, 255, 0));
        jTxtDT.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtDT.setText("0x000");
        jTxtDT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtDTActionPerformed(evt);
            }
        });

        jLabel22.setForeground(new java.awt.Color(0, 0, 153));
        jLabel22.setText("DT:");

        jTxtST.setBackground(new java.awt.Color(0, 0, 0));
        jTxtST.setFont(new java.awt.Font("Arial", 0, 10));
        jTxtST.setForeground(new java.awt.Color(0, 255, 0));
        jTxtST.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtST.setText("0x000");
        jTxtST.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtSTActionPerformed(evt);
            }
        });

        jLabel23.setForeground(new java.awt.Color(0, 0, 153));
        jLabel23.setText("ST:");

        javax.swing.GroupLayout jInternalDebugRegisterLayout = new javax.swing.GroupLayout(jInternalDebugRegister.getContentPane());
        jInternalDebugRegister.getContentPane().setLayout(jInternalDebugRegisterLayout);
        jInternalDebugRegisterLayout.setHorizontalGroup(
            jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxtPC, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxtSP, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(jTxtI, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                        .addGap(52, 52, 52)
                        .addComponent(jLabel19)
                        .addGap(57, 57, 57))
                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtVC, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtV9, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtV0, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtV6, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtV3, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel13)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtVA, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
                                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel10)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtV1, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE))
                                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel11)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtV4, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addComponent(jLabel12)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxtV7, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE))
                                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel21)
                                            .addComponent(jLabel14))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTxtVF, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                                            .addComponent(jTxtVD, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                            .addComponent(jLabel18)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jTxtVB))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                            .addComponent(jLabel20)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jTxtVE, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                            .addComponent(jLabel15)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(jTxtV2))
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalDebugRegisterLayout.createSequentialGroup()
                                            .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel16)
                                                .addComponent(jLabel17))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jTxtV8)
                                                .addComponent(jTxtV5, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE))))))
                            .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                                .addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxtDT, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel23)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxtST, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jInternalDebugRegisterLayout.setVerticalGroup(
            jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                .addContainerGap(67, Short.MAX_VALUE)
                .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTxtSP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(jTxtI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel19)
                        .addComponent(jLabel2))
                    .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTxtPC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)))
                .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTxtV0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10)
                            .addComponent(jTxtV1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15)
                            .addComponent(jTxtV2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jTxtV3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16)
                            .addComponent(jTxtV5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)
                            .addComponent(jTxtV4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jTxtV6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(jTxtV7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel17)
                            .addComponent(jTxtV8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jTxtV9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)
                            .addComponent(jTxtVA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18)
                            .addComponent(jTxtVB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jTxtVC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)
                            .addComponent(jTxtVD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel20)
                            .addComponent(jTxtVE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTxtVF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel21))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jInternalDebugRegisterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel22)
                            .addComponent(jTxtST, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel23)
                            .addComponent(jTxtDT, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jInternalDebugRegisterLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );

        jInternalDebugMemory.setClosable(true);
        jInternalDebugMemory.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalDebugMemory.setTitle("Debug - Memory Viewer");
        jInternalDebugMemory.setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setHorizontalScrollBar(null);

        jTxtMemory.setBackground(new java.awt.Color(0, 0, 0));
        jTxtMemory.setColumns(20);
        jTxtMemory.setEditable(false);
        jTxtMemory.setFont(new java.awt.Font("SimSun-ExtB", 0, 13));
        jTxtMemory.setForeground(new java.awt.Color(51, 255, 102));
        jTxtMemory.setRows(5);
        jScrollPane1.setViewportView(jTxtMemory);

        javax.swing.GroupLayout jInternalDebugMemoryLayout = new javax.swing.GroupLayout(jInternalDebugMemory.getContentPane());
        jInternalDebugMemory.getContentPane().setLayout(jInternalDebugMemoryLayout);
        jInternalDebugMemoryLayout.setHorizontalGroup(
            jInternalDebugMemoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalDebugMemoryLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jInternalDebugMemoryLayout.setVerticalGroup(
            jInternalDebugMemoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
        );

        jInternalDissambler.setClosable(true);
        jInternalDissambler.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalDissambler.setTitle("Debug - Dissambler");
        jInternalDissambler.setVisible(true);

        jBtnRun.setMnemonic('R');
        jBtnRun.setText("Run");
        jBtnRun.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnRunActionPerformed(evt);
            }
        });

        jBtnPause.setMnemonic('P');
        jBtnPause.setText("Pause");
        jBtnPause.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnPauseActionPerformed(evt);
            }
        });

        jBtnStep.setMnemonic('S');
        jBtnStep.setText("Step");
        jBtnStep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnStepActionPerformed(evt);
            }
        });

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setHorizontalScrollBar(null);

        jTxtDissambler.setBackground(new java.awt.Color(0, 0, 0));
        jTxtDissambler.setColumns(20);
        jTxtDissambler.setFont(new java.awt.Font("SimSun-ExtB", 0, 13));
        jTxtDissambler.setForeground(new java.awt.Color(51, 255, 0));
        jTxtDissambler.setRows(5);
        jScrollPane2.setViewportView(jTxtDissambler);

        jBtnClear.setMnemonic('C');
        jBtnClear.setText("Clear");
        jBtnClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnClearActionPerformed(evt);
            }
        });

        jBtnStop.setMnemonic('o');
        jBtnStop.setText("Stop");
        jBtnStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnStopActionPerformed(evt);
            }
        });

        jBtnRefresh.setMnemonic('e');
        jBtnRefresh.setText("Refresh");
        jBtnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnRefreshActionPerformed(evt);
            }
        });

        jBtnShowAssembler.setMnemonic('b');
        jBtnShowAssembler.setText("Show Assembler");
        jBtnShowAssembler.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnShowAssemblerActionPerformed(evt);
            }
        });

        jBtnReset.setMnemonic('T');
        jBtnReset.setText("Reset");
        jBtnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jInternalDissamblerLayout = new javax.swing.GroupLayout(jInternalDissambler.getContentPane());
        jInternalDissambler.getContentPane().setLayout(jInternalDissamblerLayout);
        jInternalDissamblerLayout.setHorizontalGroup(
            jInternalDissamblerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalDissamblerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalDissamblerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
                    .addGroup(jInternalDissamblerLayout.createSequentialGroup()
                        .addComponent(jBtnRun)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBtnPause)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBtnStop)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBtnStep)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBtnReset))
                    .addGroup(jInternalDissamblerLayout.createSequentialGroup()
                        .addComponent(jBtnShowAssembler)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBtnClear)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBtnRefresh)))
                .addContainerGap())
        );
        jInternalDissamblerLayout.setVerticalGroup(
            jInternalDissamblerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalDissamblerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalDissamblerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtnRun)
                    .addComponent(jBtnPause)
                    .addComponent(jBtnStop)
                    .addComponent(jBtnStep)
                    .addComponent(jBtnReset))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalDissamblerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtnClear)
                    .addComponent(jBtnRefresh)
                    .addComponent(jBtnShowAssembler))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
                .addContainerGap())
        );

        jInternalConfiguration.setClosable(true);
        jInternalConfiguration.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalConfiguration.setTitle("Configuration");
        jInternalConfiguration.setOpaque(true);
        jInternalConfiguration.setVisible(true);

        jSliderSpeed.setMaximum(1000);
        jSliderSpeed.setMinimum(1);
        jSliderSpeed.setValue(1000);

        jLabel24.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel24.setText("Speed   (MAX.                            MIN.)");

        jCboBackgroundColor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "BLACK", "BLUE", "CYAN", "DARK_GRAY", "GREEN", "MAGENTA", "ORANGE", "RED", "WHITE", "YELLOW" }));
        jCboBackgroundColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCboBackgroundColorActionPerformed(evt);
            }
        });

        jCboObjectsColor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "BLACK", "BLUE", "CYAN", "DARK_GRAY", "GREEN", "MAGENTA", "ORANGE", "RED", "WHITE", "YELLOW" }));
        jCboObjectsColor.setSelectedIndex(4);
        jCboObjectsColor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCboObjectsColorActionPerformed(evt);
            }
        });

        jCboPixelShape.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Rectangle", "3DRectangle", "Oval", "Rectangle filled", "3DRectangle filled", "Oval filled" }));
        jCboPixelShape.setSelectedIndex(3);

        jLabel25.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel25.setText("BackGround");

        jLabel26.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel26.setText("Objects");

        jLabel27.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel27.setText("Pixel Shape");

        jTxt0x01.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x01.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x01.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x01.setText("1");
        jTxt0x01.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxt0x01ActionPerformed(evt);
            }
        });
        jTxt0x01.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x01KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x01KeyReleased(evt);
            }
        });

        jLabel29.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel29.setText("Screen Size");

        jCboScreenSize.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1x", "2x", "3x", "4x", "5x", "6x" }));
        jCboScreenSize.setSelectedIndex(5);

        jTxt0x02.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x02.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x02.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x02.setText("2");
        jTxt0x02.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x02KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x02KeyReleased(evt);
            }
        });

        jTxt0x03.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x03.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x03.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x03.setText("3");
        jTxt0x03.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x03KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x03KeyReleased(evt);
            }
        });

        jTxt0xC.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0xC.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0xC.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0xC.setText("4");
        jTxt0xC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxt0xCActionPerformed(evt);
            }
        });
        jTxt0xC.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0xCKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0xCKeyReleased(evt);
            }
        });

        jTxt0xD.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0xD.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0xD.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0xD.setText("r");
        jTxt0xD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxt0xDActionPerformed(evt);
            }
        });
        jTxt0xD.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0xDKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0xDKeyReleased(evt);
            }
        });

        jTxt0x06.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x06.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x06.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x06.setText("e");
        jTxt0x06.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x06KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x06KeyReleased(evt);
            }
        });

        jTxt0x05.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x05.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x05.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x05.setText("w");
        jTxt0x05.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x05KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x05KeyReleased(evt);
            }
        });

        jTxt0x04.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x04.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x04.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x04.setText("q");
        jTxt0x04.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x04KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x04KeyReleased(evt);
            }
        });

        jTxt0x07.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x07.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x07.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x07.setText("a");
        jTxt0x07.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x07KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x07KeyReleased(evt);
            }
        });

        jTxt0x08.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x08.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x08.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x08.setText("s");
        jTxt0x08.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxt0x08ActionPerformed(evt);
            }
        });
        jTxt0x08.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x08KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x08KeyReleased(evt);
            }
        });

        jTxt0x09.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x09.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x09.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x09.setText("d");
        jTxt0x09.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x09KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x09KeyReleased(evt);
            }
        });

        jTxt0xE.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0xE.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0xE.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0xE.setText("f");
        jTxt0xE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxt0xEActionPerformed(evt);
            }
        });
        jTxt0xE.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0xEKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0xEKeyReleased(evt);
            }
        });

        jTxt0xF.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0xF.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0xF.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0xF.setText("v");
        jTxt0xF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxt0xFActionPerformed(evt);
            }
        });
        jTxt0xF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0xFKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0xFKeyReleased(evt);
            }
        });

        jTxt0xB.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0xB.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0xB.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0xB.setText("c");
        jTxt0xB.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0xBKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0xBKeyReleased(evt);
            }
        });

        jTxt0x00.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0x00.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0x00.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0x00.setText("x");
        jTxt0x00.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0x00KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0x00KeyReleased(evt);
            }
        });

        jTxt0xA.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxt0xA.setForeground(new java.awt.Color(0, 0, 153));
        jTxt0xA.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxt0xA.setText("z");
        jTxt0xA.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxt0xAKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxt0xAKeyReleased(evt);
            }
        });

        jLabel30.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel30.setText("0x1");

        jLabel31.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel31.setText("0x2");

        jLabel32.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel32.setText("0x3");

        jLabel33.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel33.setText("0xC");

        jLabel34.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel34.setText("0xD");

        jLabel35.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel35.setText("0x6");

        jLabel36.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel36.setText("0x5");

        jLabel37.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel37.setText("0x4");

        jLabel38.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel38.setText("0x7");

        jLabel39.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel39.setText("0x8");

        jLabel40.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel40.setText("0x9");

        jLabel41.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel41.setText("0xE");

        jLabel42.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel42.setText("0xF");

        jLabel43.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel43.setText("0x0");

        jLabel44.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel44.setText("0xB");

        jLabel45.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel45.setText("0xA");

        jBtnApplyConfiguration.setText("Apply");
        jBtnApplyConfiguration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnApplyConfigurationActionPerformed(evt);
            }
        });

        jLabel28.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel28.setText("Controller Layout (still not config.)");

        jLabel46.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel46.setText("Just draw the screen at");

        jTxtFrames.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTxtFrames.setForeground(new java.awt.Color(0, 0, 153));
        jTxtFrames.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTxtFrames.setText("1");
        jTxtFrames.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTxtFramesKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTxtFramesKeyReleased(evt);
            }
        });

        jLabel47.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel47.setText("calling from dwr instruction.");

        javax.swing.GroupLayout jInternalConfigurationLayout = new javax.swing.GroupLayout(jInternalConfiguration.getContentPane());
        jInternalConfiguration.getContentPane().setLayout(jInternalConfigurationLayout);
        jInternalConfigurationLayout.setHorizontalGroup(
            jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jSliderSpeed, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel28, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalConfigurationLayout.createSequentialGroup()
                                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addComponent(jTxt0x01, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0x02, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0x03, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                                .addGap(58, 58, 58)
                                                .addComponent(jLabel36)
                                                .addGap(34, 34, 34)
                                                .addComponent(jLabel35))
                                            .addComponent(jLabel37))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(jLabel34))
                                    .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel33)
                                        .addComponent(jTxt0xC, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalConfigurationLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel30))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalConfigurationLayout.createSequentialGroup()
                                .addGap(68, 68, 68)
                                .addComponent(jLabel31)
                                .addGap(34, 34, 34)
                                .addComponent(jLabel32))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalConfigurationLayout.createSequentialGroup()
                                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addComponent(jTxt0x04, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0x05, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0x06, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                                .addGap(58, 58, 58)
                                                .addComponent(jLabel39)
                                                .addGap(34, 34, 34)
                                                .addComponent(jLabel40))
                                            .addComponent(jLabel38))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(jLabel41))
                                    .addComponent(jTxt0xD, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalConfigurationLayout.createSequentialGroup()
                                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addComponent(jTxt0x07, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0x08, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0x09, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                                .addGap(58, 58, 58)
                                                .addComponent(jLabel43)
                                                .addGap(34, 34, 34)
                                                .addComponent(jLabel44))
                                            .addComponent(jLabel45)))
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addComponent(jTxt0xA, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0x00, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTxt0xB, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(jLabel42))
                                    .addComponent(jTxt0xE, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                                    .addComponent(jTxt0xF))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jBtnApplyConfiguration, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jCboPixelShape, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel25)
                                    .addComponent(jCboBackgroundColor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel26)
                                    .addComponent(jCboObjectsColor, 0, 168, Short.MAX_VALUE)
                                    .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jCboScreenSize, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                            .addComponent(jLabel27)
                                            .addGap(68, 68, 68)
                                            .addComponent(jLabel29)))))))
                    .addComponent(jLabel24)
                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                        .addComponent(jLabel46)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxtFrames, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel47)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jInternalConfigurationLayout.setVerticalGroup(
            jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                        .addComponent(jSliderSpeed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel28)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel31)
                            .addComponent(jLabel32)
                            .addComponent(jLabel30)
                            .addComponent(jLabel33, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(4, 4, 4)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTxt0x01, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0x02, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0x03, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0xC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(2, 2, 2)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel36)
                            .addComponent(jLabel35)
                            .addComponent(jLabel37)
                            .addComponent(jLabel34))
                        .addGap(2, 2, 2)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTxt0x04, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0x05, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0x06, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0xD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel39)
                            .addComponent(jLabel40)
                            .addComponent(jLabel38)
                            .addComponent(jLabel41))
                        .addGap(3, 3, 3)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTxt0x07, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0x08, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0x09, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0xE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel43)
                            .addComponent(jLabel44)
                            .addComponent(jLabel45)
                            .addComponent(jLabel42))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTxt0xA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0x00, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0xB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTxt0xF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel27)
                            .addComponent(jLabel29))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCboPixelShape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jCboScreenSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel25)
                        .addGap(4, 4, 4)
                        .addComponent(jCboBackgroundColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                .addGap(112, 112, 112)
                                .addComponent(jBtnApplyConfiguration))
                            .addGroup(jInternalConfigurationLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel26)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCboObjectsColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalConfigurationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel46)
                    .addComponent(jTxtFrames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel47))
                .addContainerGap(59, Short.MAX_VALUE))
        );

        jMenu1.setText("File");

        jMenuItem2.setText("Load");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jInternalDebugRegister)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jInternalConfiguration))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jInternalDissambler)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jInternalDebugMemory)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jInternalDebugRegister, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jInternalConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jInternalDissambler, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jInternalDebugMemory))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void refresh() {
        jTxtI.setText(Util.FormatHexAdress( emulator.CPU().addressRegisterI, true));
        jTxtPC.setText(Util.FormatHexAdress( emulator.CPU().programCounter, true));
        jTxtSP.setText(Util.FormatHexNumber(1, emulator.CPU().stackPointer, true));
        jTxtV0.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[0], true));
        jTxtV1.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[1], true));
        jTxtV2.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[2], true));
        jTxtV3.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[3], true));
        jTxtV4.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[4], true));
        jTxtV5.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[5], true));
        jTxtV6.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[6], true));
        jTxtV7.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[7], true));
        jTxtV8.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[8], true));
        jTxtV9.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[9], true));
        jTxtVA.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[10], true));
        jTxtVB.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[11], true));
        jTxtVC.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[12], true));
        jTxtVD.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[13], true));
        jTxtVE.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[14], true));
        jTxtVF.setText(Util.FormatHexValue( emulator.CPU().dataRegister.V[15], true));
        jTxtDT.setText(Util.FormatHexValue( emulator.CPU().delayTimerDT,true));
        jTxtST.setText(Util.FormatHexValue( emulator.CPU().soundTimerST,true));

        jTxtMemory.setText(emulator.showProgramMemory());
        jTxtStack.setText(emulator.stack());
        jTxtMemory.setCaretPosition(1);
        jTxtStack.setCaretPosition(1);
    }

    private JFileChooser makeJFileChooser() {
        final JFileChooser fc = new JFileChooser();
        fc.setDialogTitle("Open CHIP8 File");
        fc.setCurrentDirectory(new java.io.File("."));
        return fc;
    }

    private boolean userChooseSomething(int returnVal) {
        return returnVal == JFileChooser.APPROVE_OPTION;
    }

    private void jBtnStepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnStepActionPerformed
        emulator.step();
        String actualAssembler = emulator.showCurrentAssembler();
        if (!actualAssembler.equals("")) {
            jTxtDissambler.setText(jTxtDissambler.getText() + "\n" + actualAssembler);
        }
        refresh();
}//GEN-LAST:event_jBtnStepActionPerformed

    private void jBtnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnClearActionPerformed
        jTxtDissambler.setText("");

}//GEN-LAST:event_jBtnClearActionPerformed
    private ScreenJava2D scn = new ScreenJava2D(500,500);
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed

        if (scn != null) {
            scn.dispose();
        }

        scn = new ScreenJava2D(500,500);

        if (emulatorThread != null) {
            try {
                Emulator.stop();
                Thread.sleep(500);
                Emulator.init();
                emulatorThread = null;
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if (ChooseFile())
        {
            LoadFile(lastFileSelected);
            refresh();
            Emulator.stop();
            Emulator.init();
            emulatorThread = new Thread(emulator);
        } 
        else
        {
            return;
        }
}//GEN-LAST:event_jMenuItem2ActionPerformed

    private void Restart()
    {
        if (emulatorThread != null) {
            try {
                Emulator.stop();
                Thread.sleep(500);
                Emulator.init();
                emulatorThread = null;
                //Thread.sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if (lastFileSelected != null)
        {
            LoadFile(lastFileSelected);
            emulator.ClearScreen();
            refresh();
            Emulator.stop();
            Emulator.init();
            emulatorThread = new Thread(emulator);
        }
        else
        {
            return;
        }
    }

    private boolean ChooseFile()
    {
        final JFileChooser fc = makeJFileChooser();
        int returnVal = fc.showOpenDialog(this);

        boolean userHasChosenFile = userChooseSomething(returnVal);
        if(userHasChosenFile)
            lastFileSelected =  fc.getSelectedFile();

        return userHasChosenFile;
    }

    private void LoadFile(File file)
    {
            FileChannel roChannel;
            ByteBuffer readbuffer = null;
            try {
                roChannel = new RandomAccessFile(file, "r").getChannel();
                try {
                    readbuffer = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) roChannel.size());
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
            scn.setVisible(true);
            emulator = new Emulator(scn.getJava2D());
            emulator.fillMemory(readbuffer, file.length());
    }

    private void jTxtIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtIActionPerformed
        JTextField txtField = (JTextField)evt.getSource();
        int newValue = Integer.parseInt(txtField.getText().substring(2),16);
        emulator.CPU().addressRegisterI = (short)(newValue&0xfff);

        refresh();
}//GEN-LAST:event_jTxtIActionPerformed

    private void jBtnRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnRunActionPerformed
        if(!fileToLoad.isEmpty())
        {
          LoadFile(new File(fileToLoad));
        }

        if (emulatorThread == null) {
            emulatorThread = new Thread(emulator);
        }
        emulatorThread.start();
        SetButtonStates(false,false);
}//GEN-LAST:event_jBtnRunActionPerformed

    private void jBtnPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnPauseActionPerformed
        Emulator.pause();
        SetButtonStates(true,true);
        renewDisassemblerListing();
        refresh(); // refreshes all registers and memory window
       
}//GEN-LAST:event_jBtnPauseActionPerformed

    private void jBtnStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnStopActionPerformed
        Emulator.stop();
        SetButtonStates(true,true);
}//GEN-LAST:event_jBtnStopActionPerformed

    private void jBtnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnRefreshActionPerformed
        renewDisassemblerListing();
        refresh();
}//GEN-LAST:event_jBtnRefreshActionPerformed

    private void renewDisassemblerListing()
    {
        String actualAssembler = "";
        if(emulator != null)
            actualAssembler = emulator.showCurrentAssembler();

        jTxtDissambler.setText("");
        jTxtDissambler.setText(actualAssembler);
    }

    private void jBtnShowAssemblerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnShowAssemblerActionPerformed
        WindowDisassembler dissambler = new WindowDisassembler();

        //dissambler.addActionListener(new MultiHighlight(dissambler, "aeiouAEIOU"));
        renewDisassemblerListing();
        dissambler.setEmulator(emulator);
        dissambler.setVisible(true);
}//GEN-LAST:event_jBtnShowAssemblerActionPerformed

    private void jTxt0x01KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x01KeyPressed
}//GEN-LAST:event_jTxt0x01KeyPressed

    private void jTxt0x01KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x01KeyReleased
}//GEN-LAST:event_jTxt0x01KeyReleased

    private void jTxt0x02KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x02KeyPressed
}//GEN-LAST:event_jTxt0x02KeyPressed

    private void jTxt0x02KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x02KeyReleased
}//GEN-LAST:event_jTxt0x02KeyReleased

    private void jTxt0x03KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x03KeyPressed
}//GEN-LAST:event_jTxt0x03KeyPressed

    private void jTxt0x03KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x03KeyReleased
}//GEN-LAST:event_jTxt0x03KeyReleased

    private void jTxt0xCKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xCKeyPressed
}//GEN-LAST:event_jTxt0xCKeyPressed

    private void jTxt0xCKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xCKeyReleased
}//GEN-LAST:event_jTxt0xCKeyReleased

    private void jTxt0xDKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xDKeyPressed
}//GEN-LAST:event_jTxt0xDKeyPressed

    private void jTxt0xDKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xDKeyReleased
}//GEN-LAST:event_jTxt0xDKeyReleased

    private void jTxt0x06KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x06KeyPressed
}//GEN-LAST:event_jTxt0x06KeyPressed

    private void jTxt0x06KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x06KeyReleased
}//GEN-LAST:event_jTxt0x06KeyReleased

    private void jTxt0x05KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x05KeyPressed
}//GEN-LAST:event_jTxt0x05KeyPressed

    private void jTxt0x05KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x05KeyReleased
        // TODO add your handling code here:
}//GEN-LAST:event_jTxt0x05KeyReleased

    private void jTxt0x04KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x04KeyPressed
}//GEN-LAST:event_jTxt0x04KeyPressed

    private void jTxt0x04KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x04KeyReleased
}//GEN-LAST:event_jTxt0x04KeyReleased

    private void jTxt0x07KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x07KeyPressed
}//GEN-LAST:event_jTxt0x07KeyPressed

    private void jTxt0x07KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x07KeyReleased
}//GEN-LAST:event_jTxt0x07KeyReleased

    private void jTxt0x08KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x08KeyPressed
}//GEN-LAST:event_jTxt0x08KeyPressed

    private void jTxt0x08KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x08KeyReleased
}//GEN-LAST:event_jTxt0x08KeyReleased

    private void jTxt0x09KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x09KeyPressed
}//GEN-LAST:event_jTxt0x09KeyPressed

    private void jTxt0x09KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x09KeyReleased
}//GEN-LAST:event_jTxt0x09KeyReleased

    private void jTxt0xEKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xEKeyPressed
}//GEN-LAST:event_jTxt0xEKeyPressed

    private void jTxt0xEKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xEKeyReleased
}//GEN-LAST:event_jTxt0xEKeyReleased

    private void jTxt0xFKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xFKeyPressed
}//GEN-LAST:event_jTxt0xFKeyPressed

    private void jTxt0xFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xFKeyReleased
}//GEN-LAST:event_jTxt0xFKeyReleased

    private void jTxt0xBKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xBKeyPressed
}//GEN-LAST:event_jTxt0xBKeyPressed

    private void jTxt0xBKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xBKeyReleased
}//GEN-LAST:event_jTxt0xBKeyReleased

    private void jTxt0x00KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x00KeyPressed
}//GEN-LAST:event_jTxt0x00KeyPressed

    private void jTxt0x00KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0x00KeyReleased
}//GEN-LAST:event_jTxt0x00KeyReleased

    private void jTxt0xAKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xAKeyPressed
}//GEN-LAST:event_jTxt0xAKeyPressed

    private void jTxt0xAKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxt0xAKeyReleased
}//GEN-LAST:event_jTxt0xAKeyReleased

    private void jCboBackgroundColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCboBackgroundColorActionPerformed
}//GEN-LAST:event_jCboBackgroundColorActionPerformed

    private void jCboObjectsColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCboObjectsColorActionPerformed
}//GEN-LAST:event_jCboObjectsColorActionPerformed

    private void jBtnApplyConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnApplyConfigurationActionPerformed
        Engine.background = getColor(jCboBackgroundColor.getSelectedItem().toString());
        // resize Chip-8 output screen according to current selections.
        int chosenSize =  Integer.valueOf(jCboScreenSize.getSelectedItem().toString().substring(0,1));
        scn.dispose();
        scn = new ScreenJava2D(31+(64*chosenSize), 52+(32*chosenSize));
        
        scn.getJava2D().drawRect(0, 0, scn.getJPanelJava2D().getSize().width, scn.getJPanelJava2D().getSize().height);
        scn.getJava2D().fillRect(0, 0, scn.getJPanelJava2D().getSize().width, scn.getJPanelJava2D().getSize().height);
        scn.setVisible(true);
        Engine.objects = getColor(jCboObjectsColor.getSelectedItem().toString());
        Engine.streetch = Integer.valueOf(jCboScreenSize.getSelectedItem().toString().substring(0, 1));
        Engine.pixelShape = jCboPixelShape.getSelectedItem().toString();
        Emulator.setSpeed(jSliderSpeed.getValue());
        Engine.callingNumber = Integer.valueOf(jTxtFrames.getText());
        Engine.justDrawAtFrame = 0x0;
}//GEN-LAST:event_jBtnApplyConfigurationActionPerformed

    private void jTxt0xCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxt0xCActionPerformed
}//GEN-LAST:event_jTxt0xCActionPerformed

    private void jTxt0xDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxt0xDActionPerformed
}//GEN-LAST:event_jTxt0xDActionPerformed

    private void jTxt0x08ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxt0x08ActionPerformed
}//GEN-LAST:event_jTxt0x08ActionPerformed

    private void jTxt0xEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxt0xEActionPerformed
}//GEN-LAST:event_jTxt0xEActionPerformed

    private void jTxt0x01ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxt0x01ActionPerformed
}//GEN-LAST:event_jTxt0x01ActionPerformed

    private void jTxt0xFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxt0xFActionPerformed
}//GEN-LAST:event_jTxt0xFActionPerformed

    private void jTxtFramesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxtFramesKeyPressed
}//GEN-LAST:event_jTxtFramesKeyPressed

    private void jTxtFramesKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxtFramesKeyReleased
}//GEN-LAST:event_jTxtFramesKeyReleased

    private void jBtnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnResetActionPerformed
        //emulator.resetWithoutMemClear();

         if(!fileToLoad.isEmpty())
            LoadFile(new File(fileToLoad));

        refresh();
        jTxtDissambler.setText("");
        Restart();
        SetButtonStates(true,true);
    }//GEN-LAST:event_jBtnResetActionPerformed

    private void jTxtVRegActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtVRegActionPerformed
       JTextField txtField = (JTextField)evt.getSource();
       int regNumber = Integer.parseInt(txtField.getToolTipText());
       int newValue = Integer.parseInt(txtField.getText().substring(2),16);
       emulator.CPU().dataRegister.V[regNumber] = (short)(newValue&0xff);
       refresh();
    }//GEN-LAST:event_jTxtVRegActionPerformed

    private void jTxtSPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtSPActionPerformed
       JTextField txtField = (JTextField)evt.getSource();
       int newValue = Integer.parseInt(txtField.getText().substring(2),16);
       emulator.CPU().stackPointer = (short)(newValue&0xf);
       refresh();
    }//GEN-LAST:event_jTxtSPActionPerformed

    private void jTxtPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtPCActionPerformed
        JTextField txtField = (JTextField)evt.getSource();
       int newValue = Integer.parseInt(txtField.getText().substring(2),16);
       emulator.CPU().programCounter = (short)(newValue&0xfff);
       refresh();
    }//GEN-LAST:event_jTxtPCActionPerformed

    private void jTxtDTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtDTActionPerformed
        JTextField txtField = (JTextField)evt.getSource();
       int newValue = Integer.parseInt(txtField.getText().substring(2),16);
       emulator.CPU().delayTimerDT = (short)(newValue&0xff);
       refresh();
    }//GEN-LAST:event_jTxtDTActionPerformed

    private void jTxtSTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtSTActionPerformed
        JTextField txtField = (JTextField)evt.getSource();
       int newValue = Integer.parseInt(txtField.getText().substring(2),16);
       emulator.CPU().soundTimerST = (short)(newValue&0xff);
       refresh();
    }//GEN-LAST:event_jTxtSTActionPerformed

   
    public static void main(String[] args ) {
        if (args.length == 1)
        {
            Main.fileToLoad = args[0];
        }
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnApplyConfiguration;
    private javax.swing.JButton jBtnClear;
    private javax.swing.JButton jBtnPause;
    private javax.swing.JButton jBtnRefresh;
    private javax.swing.JButton jBtnReset;
    private javax.swing.JButton jBtnRun;
    private javax.swing.JButton jBtnShowAssembler;
    private javax.swing.JButton jBtnStep;
    private javax.swing.JButton jBtnStop;
    private javax.swing.JComboBox jCboBackgroundColor;
    private javax.swing.JComboBox jCboObjectsColor;
    private javax.swing.JComboBox jCboPixelShape;
    private javax.swing.JComboBox jCboScreenSize;
    private javax.swing.JInternalFrame jInternalConfiguration;
    private javax.swing.JInternalFrame jInternalDebugMemory;
    private javax.swing.JInternalFrame jInternalDebugRegister;
    private javax.swing.JInternalFrame jInternalDissambler;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSlider jSliderSpeed;
    private javax.swing.JTextField jTxt0x00;
    private javax.swing.JTextField jTxt0x01;
    private javax.swing.JTextField jTxt0x02;
    private javax.swing.JTextField jTxt0x03;
    private javax.swing.JTextField jTxt0x04;
    private javax.swing.JTextField jTxt0x05;
    private javax.swing.JTextField jTxt0x06;
    private javax.swing.JTextField jTxt0x07;
    private javax.swing.JTextField jTxt0x08;
    private javax.swing.JTextField jTxt0x09;
    private javax.swing.JTextField jTxt0xA;
    private javax.swing.JTextField jTxt0xB;
    private javax.swing.JTextField jTxt0xC;
    private javax.swing.JTextField jTxt0xD;
    private javax.swing.JTextField jTxt0xE;
    private javax.swing.JTextField jTxt0xF;
    private javax.swing.JTextField jTxtDT;
    private javax.swing.JTextArea jTxtDissambler;
    private javax.swing.JTextField jTxtFrames;
    private javax.swing.JTextField jTxtI;
    private javax.swing.JTextArea jTxtMemory;
    private javax.swing.JTextField jTxtPC;
    private javax.swing.JTextField jTxtSP;
    private javax.swing.JTextField jTxtST;
    private javax.swing.JTextArea jTxtStack;
    private javax.swing.JTextField jTxtV0;
    private javax.swing.JTextField jTxtV1;
    private javax.swing.JTextField jTxtV2;
    private javax.swing.JTextField jTxtV3;
    private javax.swing.JTextField jTxtV4;
    private javax.swing.JTextField jTxtV5;
    private javax.swing.JTextField jTxtV6;
    private javax.swing.JTextField jTxtV7;
    private javax.swing.JTextField jTxtV8;
    private javax.swing.JTextField jTxtV9;
    private javax.swing.JTextField jTxtVA;
    private javax.swing.JTextField jTxtVB;
    private javax.swing.JTextField jTxtVC;
    private javax.swing.JTextField jTxtVD;
    private javax.swing.JTextField jTxtVE;
    private javax.swing.JTextField jTxtVF;
    // End of variables declaration//GEN-END:variables
}
